package test.netty.client;

import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * @author cuichao
 * @Description: ClientDecode
 * @Date: create in 2020/12/21 14:51
 */
public class ClientDecode extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        int i = in.readInt();
        byte[] b = new byte[i];

        in.readBytes(b);
        InputStream inputStream = new ByteInputStream(b,b.length);

        InputStreamReader reader = new InputStreamReader(inputStream);

        String result = new String(b,CharsetUtil.UTF_8);

     /*   if(true){
            throw new NullPointerException();
        }*/
        out.add(result);
    }



}
